import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
//element-plus组件库
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
//element-plus图标库
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
//修改elementPlus默认中文
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'

const BASE_URL = 'http://localhost:8088'
window.BASE_URL = BASE_URL;
const app = createApp(App)/* 创建vue实例,并起名为app */
//给app(vue对象)页设置全局根路径,才能在任意template中使用此常量
app.config.globalProperties.BASE_URL = BASE_URL;
//将导入的图标组件变为键值对数组,并依次遍历取出每一个图标组件[key,component]
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    // 将当前遍历到的图标组件注册为当前vue实例的全局组件
    app.component(key, component)
}
//为前vue实例应用element-plus组件库
//将El本地化为中文
app.use(ElementPlus,{ locale: zhCn }).use(store).use(router).mount('#app')

//解决ResizeObserver Error
const debounce = (fn, delay) => {
    let timer = null;
    return function () {
        let context = this;
        let args = arguments;
        clearTimeout(timer);
        timer = setTimeout(function () {
            fn.apply(context, args);
        }, delay);
    }
}
const _ResizeObserver = window.ResizeObserver;
window.ResizeObserver = class ResizeObserver extends _ResizeObserver {
    constructor(callback) {
        callback = debounce(callback, 16);
        super(callback);
    }
}
window.getUser = ()=>{
    return localStorage.user ? JSON.parse(localStorage.user) : null;
}
